<!DOCTYPE html>
<html lang="zh">
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header :: header(~{::title},~{::link},~{})">
    <title>点餐</title>
    <link rel="icon" th:href="@{/assets/img/lcxm.ico}" type="image/ico">
</head>
<body class="body">
<!--导航-->
<div th:replace="common/nav :: nav(true)"></div>

<div class="container">

    <div class="row">
        <div style="margin-top: 20px;"></div>
        <div class="row">

            <form class="form-horizontal validate" role="form" method="post" th:action="@{/group/save}"
                  onsubmit="return checkForm(this);">

                <!-- 操作信息提示的地方 -->
                <div th:if="${remind}" class="alert alert-${ remind.level  }"
                     th:classappend="'alert-' + ${remind.level}">
                    <button data-dismiss="alert" class="close" type="button">
                        <i class="glyphicon glyphicon-remove"></i>
                    </button>
                    <span th:remove="tag" th:utext="${ remind.message }"></span>
                </div>


                <div class="form-group">
                    <label for="name" class="col-md-1 col-sm-1 control-label">用户名</label>
                    <div class="col-sm-9  col-md-9  ">
                        <input type="hidden" class="form-control" id="id" name="id" th:value="${entity?.id}" />
                        <input type="text" class="form-control" id="name"  name="name" th:value="${entity?.name}"
                               placeholder="名称唯一" autocomplete="off" />
                    </div>
                    <div class="col-md-2 col-sm-2  help-inline form-control-static"></div>
                </div>

                <div class="form-group">
                    <label for="note" class="col-md-1 col-sm-1 control-label">备注</label>
                    <div class="col-sm-9  col-md-9  ">
                        <input type="text" class="form-control" id="note"  name="note" th:value="${entity?.note}"
                               placeholder="备注" autocomplete="off" />
                    </div>
                    <div class="col-md-2 col-sm-2  help-inline form-control-static"></div>
                </div>



                <hr/>

                <div class="form-group clearfix">
                    <div class="text-center col-sm-9">

                        <button th:if="${remind == null}" type="submit" class="btn btn-lg btn-primary">
                            <i class="glyphicon glyphicon-ok"></i> 提交
                        </button>

                        <a type="button" class="btn btn-lg  btn-info" th:href="@{/report/}">
                            <i class="glyphicon glyphicon-repeat"></i> 返回
                        </a>
                    </div>
                </div>

            </form>


        </div>


    </div>
</div>

<!-- 引入通用js-->
<div th:replace="common/footer :: footer"></div>
<script>
    function checkForm(form) {
        var $form = $(form);
        var name = $("#name").val();
        var note = $("#note").val();

        if (name && note) {
            var check = true;
            //校验name
            $.ajax({
                async: false,
                url: ctx + 'group/checkName',
                type: 'post',
                data: {
                    name: name,
                    id: $("#id").val()
                },
                success: function (data) {
                    if (!data.data) {
                        $.alert({
                            theme: 'bootstrap',
                            title: '温馨提示',
                            content: "小组已存在"
                        });
                        check = false;
                    }
                }
            });
            return check;
        }

        $.alert({
            theme: 'bootstrap',
            title: '温馨提示',
            content: '请完整填写小组信息'
        });

        return false;
    };



</script>

</body>
</html>